package com.growthsee.rider.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.growthsee.common.core.controller.BaseController;
import com.growthsee.common.core.page.PageDomain;
import com.growthsee.common.core.page.TableDataInfo;
import com.growthsee.rider.domain.RiderPushLog;
import com.growthsee.rider.param.DateTimeParam;
import com.growthsee.rider.service.RiderPushLogService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 推送日志 前端控制器
 * </p>
 *
 * @author csy
 * @since 2021-06-11
 */
@AllArgsConstructor
@RestController
@RequestMapping("/rider/riderPushLog")
public class RiderPushLogController extends BaseController {

    private final RiderPushLogService riderPushLogService;

    @GetMapping
    public TableDataInfo query(PageDomain page, DateTimeParam dateTimeParam) {
        LambdaQueryWrapper queryWrapper = Wrappers.<RiderPushLog>lambdaQuery();
        if(ObjectUtils.isNotEmpty(dateTimeParam.getBeginTime())){
            queryWrapper.apply( "date_format (create_time,'%Y-%m-%d %H:%i:%s') >= date_format('" + dateTimeParam.getBeginTime() + "','%Y-%m-%d %H:%i:%s')");
        }
        if(ObjectUtils.isNotEmpty(dateTimeParam.getEndTime())){
            queryWrapper.apply( "date_format (create_time,'%Y-%m-%d %H:%i:%s') >= date_format('" + dateTimeParam.getEndTime() + "','%Y-%m-%d %H:%i:%s')");
        }
        Page page1 = riderPushLogService.page(new Page<>(page.getPageNum(),page.getPageSize()), queryWrapper);
        return getDataTable(page1.getRecords(),page1.getTotal());
    }

}

